<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="UTF-8">
	<title>分店管理-门禁管理</title>
	<link rel="stylesheet" href="/js/plugin/layui-v2.3.0/layui/css/layui.css">
	<link rel="stylesheet" href="/css/reset.css">
	<link rel="stylesheet" href="/css/index.css">
	<script src="/js/jquery-2.1.1.min.js"></script>
	<script src="/js/plugin/layui-v2.3.0/layui/layui.js"></script>
	<script src="/js/common.js"></script>
</head>
<style>
/* ::-webkit-scrollbar-thumb {
  background:rgb(95,106,135); 
  border-radius: 10px;
  height:50%;
} */
body{
	height: auto; 
}
.date-input {
    padding-left: 30px;
    background: url(/images/icon/rili_icon.png) no-repeat 10px center !important;
}
.layui-form-label{
    width:auto;
	padding:9px 4px;
	text-align:right;
}
</style>
<script>
	//重新渲染表单
	function renderForm(){
	    layui.use('form', function(){
	       var form = layui.form;//高版本建议把括号去掉，有的低版本，需要加()
	       form.render();
	    });
	}
	
	function addDoor(){
		var projectId = parent.parent.$("#projectId").val();
		parent.parent.layer.open({
		  type: 2, 
		  title:["添加门禁权限", 'font-size:22px;color:#666;height:60px;line-height:60px;'],
		  area: ['626px','93%'],
	      shade: [0.6, '#010101'],
	      zIndex:1000,
		  content:"/app/projectDoor/toAdd/"+projectId , 
		  end: function () {
			  
	      }
		});
	}
</script>
<body>
	<div class="nav-section-content-container" style="padding: 0px">
		<header class="nav-header">
			<div class="nav-section-header-title">
				<span>门禁管理</span>
				<div class="f-right">
				    <button class="layui-btn layui-btn-radius layui-btn-normal " id="add_door" onclick="addDoor()">添加门禁权限</button>
				</div>
			</div>
		</header>
		<div class="nav-section-content-container">
			<div class="m-updown">
				<div class="nav-section-action-bar" >
					<table class="layui-hide" id="LAY_table_door" lay-filter="door"></table> 
					<script id="Bar" type="text/html">
  						<a  onmouseenter=tipHover(this,"修改") onmouseleave=closeAll() onclick="edit('{{d.id}}',event)" data-id="{{d.id}}"><i class="layui-icon icon-settings">&#xe642;</i></a>
					</script>
					<script id="networkType" type="text/html">
  						{{# if(d.networkType == '' || d.networkType == null ){ }}
							<span data-id="{{d.id}}">不联网</span>
						{{# }else{ }}
							<span data-id="{{d.id}}">联网</span>
						{{# } }}
					</script>
					<script id="areaName" type="text/html">
  						{{# if(d.areaId == 'door' ){ }}
							大门
						{{# }else{ }}
							{{d.name}}
						{{# } }}
					</script>
				</div>
			</div>
		</div>
	</div>
</body>
<script>
var table,startDate;
$(function(){
	setHeight();
	var projectId=parent.parent.$("#projectId").val();
	layui.use(['element','layer','form','table', 'laydate'], function(){
		var form = layui.form,laydate = layui.laydate;
		table = layui.table;
		
		//日期
		laydate.render({
		    elem: '#bookDate'
		    ,range:'~'
		    ,done: function(value, date){
		    }
		});
		//方法级渲染
		table.render({
			id:'door',
		    elem: '#LAY_table_door',
		    url: '/app/projectDoor/listdata',
		    cols: [[
			      //{checkbox: true, fixed: true},
			      {field:'deviceId', align:'left', title: '门禁设备编号',width:'20%'}
			      ,{field:'name',align:'left', title: '名称',width:'15%'}
			      ,{field:'networkType', align:'left', title: '联网类型',width:'15%',toolbar: '#networkType' }
			      ,{field:'areaId', align:'left', title: '所在区域',width:'25%',toolbar: '#areaName'}
			      ,{field:'enabledState', align:'center',width:'20%',toolbar: '#Bar' }
			    ]]
		    ,page: true
		    ,where: {
	        	params:{
	        		pid:projectId
	        	}
	        },done:function(){
	        	$(".layui-table-body table.layui-table td").css("cursor","pointer");
	        	setHeight();
	        }
		});
		tableBtnOpt();
	})
})
function reloadList(){
	table.reload('door', {
        page: {
          curr: 1 //重新从第 1 页开始
        }
        ,where: {
        	params:{
        		
        	}
        },
        done:function(){
        	setHeight();
        }
    });
}
function edit(id,event){
	preventBubble(event);//阻止事件冒泡即可，点击tr的
	parent.parent.layer.open({
	  type: 2, 
	  title:"修改门禁",
	  area: ['700px','90%'],
      shade: [0.6, '#010101'],
      zIndex:800,
	  content:"/app/projectDoor/edit/"+id , 
	  end: function () {
		  tableBtnOpt();
      }
	});
}
/* 阻止事件冒泡 */
function preventBubble(event){ //取消事件冒泡
	  var e=arguments.callee.caller.arguments[0]||event; //若省略此句，下面的e改为event，IE运行可以，但是其他浏览器就不兼容  
	  if (e && e.stopPropagation) {  
	    e.stopPropagation();  
	  } else if (event) {  
	    event.cancelBubble = true;  
	  }  
}
function tableBtnOpt(){
	var $mylist = $("#LAY_table_door").next('.layui-table-view').find('.layui-table-body table.layui-table');
  	/*  点击tr元素,跳转详情基于table*/
	  $mylist.on("click",'tr',function(){
			var targetI=$(this);
			//$(this).parent().find("i[isShow='fou']")
			var id=$(targetI).children('td').find("span[data-id]").attr("data-id");
			console.log(id);
			location.href='/app/projectDoor/details/'+id;
			return false;
	  });
}
function tipHover(target,txt){
	var index=layer.tips(txt,target, {
		  tips: [1, '#000'],
		  area: ['auto', 'auto'],
		  time: 0,
		  tipsMore: true
	});
	return index;
}
function closeAll(){
	layer.closeAll();
}
function setHeight(){
    var h = document.body.offsetHeight;
    window.parent.parentHeight(h);
}
</script>
</html>